#!/usr/bin/env python3

import tornado.web


# UIModules

class CommentModule(tornado.web.UIModule):
    def render(self, comment):
        author = self.handler.find_by_id('authors', comment['author'])
        return self.render_string('modules/comment.html',
                                  comment=comment, author=author)


class EntryModule(tornado.web.UIModule):
    def render(self, entry, limit=False):
        author = self.handler.find_by_id('authors', entry['author'])
        cmts = list(self.handler.db['comments'].find({
            'entry': str(entry['_id'])}))
        return self.render_string('modules/entry.html', limit=limit,
                                  entry=entry, author=author, comments=cmts)


class ModalModule(tornado.web.UIModule):
    def render(self, name, link):
        return self.render_string('modules/modal.html', name=name, link=link)
